package com.market.domain;

import java.util.Locale;
import java.util.ResourceBundle;

import javax.faces.context.FacesContext;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;

@Entity
@Table(name = "accountrecord")
public class AccountRecord extends BaseObject {

	/**
	 * 
	 */
	private static final long serialVersionUID = 5875449400207117203L;

	public enum TYPE {
		DEPOSIT, WITHDRAWAL, ORDER_PAID_DEPOSIT, ORDER_PAID_WITHDRAL, ORDER_PAID_PROMOTION_REWARD, ORDER_UNPAID_PROMOTION_REWARD_CANCEL, OTHER_REWARD, ORDER_USED, ORDER_CANCEL_RETURN, CORRECTION;

		private String getMessage(String key) {
			Locale locale = FacesContext.getCurrentInstance().getViewRoot()
					.getLocale();
			java.util.ResourceBundle resBundle = ResourceBundle.getBundle(
					"com.market.messages", locale);
			return resBundle.getString(key);
		}

		public String getLabel() {
			return this.getMessage("ACCOUNTRECORD_TYPE_" + this.toString());
		}
	}

	@Override
	public boolean equalsId(Object o) {
		if (o instanceof AccountRecord
				&& ((AccountRecord) o).getId().equals(this.id)) {
			return true;
		}
		return false;
	}

	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	private Long id = 0L;
	@Column(columnDefinition = "TIMESTAMP DEFAULT CURRENT_TIMESTAMP")
	private java.util.Date recordDate;
	@Enumerated(EnumType.STRING)
	private TYPE type = TYPE.DEPOSIT;
	@Column(columnDefinition = "Double default 0")
	private Double amount = 0D; // How much for this transaction.
	@Column(columnDefinition = "Double DEFAULT 0")
	private Double newBalance = 0D;
	@Column(length = 500)
	private String comments;

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public java.util.Date getRecordDate() {
		return recordDate;
	}

	public void setRecordDate(java.util.Date recordDate) {
		this.recordDate = recordDate;
	}

	public TYPE getType() {
		return type;
	}

	public void setType(TYPE type) {
		this.type = type;
	}

	public Double getAmount() {
		return amount;
	}

	public void setAmount(Double amount) {
		this.amount = amount;
	}

	public Double getNewBalance() {
		return newBalance;
	}

	public void setNewBalance(Double newBalance) {
		this.newBalance = newBalance;
	}

	public String getComments() {
		return comments;
	}

	public void setComments(String comments) {
		this.comments = comments;
	}

	@Override
	public String toString() {
		return "AccountRecord [id=" + id + ", recordDate=" + recordDate
				+ ", type=" + type + ", amount=" + amount + ", newBalance="
				+ newBalance + ", comments=" + comments + "]";
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((amount == null) ? 0 : amount.hashCode());
		result = prime * result
				+ ((comments == null) ? 0 : comments.hashCode());
		result = prime * result
				+ ((newBalance == null) ? 0 : newBalance.hashCode());
		result = prime * result
				+ ((recordDate == null) ? 0 : recordDate.hashCode());
		result = prime * result + ((type == null) ? 0 : type.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		AccountRecord other = (AccountRecord) obj;
		if (amount == null) {
			if (other.amount != null)
				return false;
		} else if (!amount.equals(other.amount))
			return false;
		if (comments == null) {
			if (other.comments != null)
				return false;
		} else if (!comments.equals(other.comments))
			return false;
		if (newBalance == null) {
			if (other.newBalance != null)
				return false;
		} else if (!newBalance.equals(other.newBalance))
			return false;
		if (recordDate == null) {
			if (other.recordDate != null)
				return false;
		} else if (!recordDate.equals(other.recordDate))
			return false;
		if (type != other.type)
			return false;
		return true;
	}

	

}
